package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-16 16:30
 **/
public class LeetCode2139 {

    public int minMoves(int target, int maxDoubles) {
        int cnt = 0;
        while (target != 1) {
            if (maxDoubles > 0) {
                cnt += 1;
                if ((target & 1) == 1) {
                    target -= 1;
                } else {
                    --maxDoubles;
                    target /= 2;
                }
            } else {
                cnt += target - 1;
                target = 1;
            }

        }

        return cnt;
    }

}
